﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Logistics
{
    
    public delegate void UpdateEventHander(WorkState state);
    public delegate void CompleteEventHander();
    public delegate void FailEventHander(FailState state);
    public interface IWorkObject
    {
        event UpdateEventHander Update;
        event CompleteEventHander Complete;
        event FailEventHander Fail;
        void DoWork();
        void Cancle();
    }

    public abstract class AbstractWorker : IWorkObject
    {
        public event UpdateEventHander Update;
        public event CompleteEventHander Complete;
        public event FailEventHander Fail;

        protected virtual void RaiseUpdate(WorkState state)
        {
            if (this.Update != null)
            {
                this.Update(state);
            }
        }
        protected virtual void RaiseComplete()
        {
            if (this.Complete != null)
            {
                this.Complete();
            }
        }
        protected virtual void RaiseFail(FailState state)
        {
            if (this.Fail != null)
            {
                this.Fail(state);
            }
        }

        public abstract void DoWork();
        public abstract void Cancle();
    }

    public class WorkState
    {
        public String WorkName{ get; set; }
        public int Process { get; set; }
        public String ProcessMsg { get; set; }
    }
    public class FailState
    {
        public String FailedMsg { get; set; }
    }
}
